package com.hwz.controller.user;

import com.hwz.dto.OrdersPaymentDTO;
import com.hwz.dto.OrdersSubmitDTO;
import com.hwz.result.PageResult;
import com.hwz.result.Result;
import com.hwz.service.OrderService;
import com.hwz.vo.OrderPaymentVO;
import com.hwz.vo.OrderSubmitVO;
import com.hwz.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * [一句话描述该类的功能]
 *
 * @author : [Lenovo]
 * @version : [v1.0]
 * @createTime : [2024/3/21 18:59]
 */
@RestController("UserOrderController")
@RequestMapping("/user/order")
@Slf4j
public class OrderController {
    @Autowired
    OrderService orderService;
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submitOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }
    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

    /**
     * 查询历史订单
     * @param page
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/historyOrders")
    public Result<PageResult> historyOrders(Integer page,Integer pageSize,Integer status){
        PageResult pageResult = orderService.historyOrders(page,pageSize,status);
        return Result.success(pageResult);
    }

    /**
     * 查询订单详情
     * @param orderId
     * @return
     */
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> getOrderDetail(@PathVariable("id") Long orderId){
        OrderVO orderVO = orderService.getOrderDetails(orderId);
        return Result.success(orderVO);
    }

    /**
     * 用户取消订单
     * @param orderId
     * @return
     * @throws Exception
     */
    @PutMapping("/cancel/{id}")
    public Result cancelOrder(@PathVariable("id") Long orderId) throws Exception {
        orderService.userCancelOrder(orderId);
        return Result.success();
    }

    @PostMapping("/repetition/{id}")
    public Result repetitionOrder(@PathVariable("id") Long orderId){
        orderService.repetitionOrder(orderId);
        return Result.success();
    }

    @GetMapping("/reminder/{id}")
    public Result reminderOrder(@PathVariable("id") Long orderId){
        orderService.reminderOrder(orderId);
        return Result.success();
    }
}
